import dayjs from 'dayjs'
export function formatDate(time: number | string | Date, type: string = 'YYYY-MM-DD HH:mm:ss') {
  return dayjs(time).format(type)
}

export function calcThirtyDays() {
  const startTime = dayjs().subtract(29, 'day').startOf('day').valueOf()
  const endTimeStamp = dayjs().endOf('day').valueOf()

  return [formatDate(startTime, 'YYYY-MM-DD HH:mm:ss'), formatDate(endTimeStamp, 'YYYY-MM-DD HH:mm:ss')]
}

export function calcDays(num: number) {
  const startTime = dayjs().subtract(num - 1, 'day').startOf('day').valueOf()
  const endTimeStamp = dayjs().endOf('day').valueOf()

  return [formatDate(startTime, 'YYYY-MM-DD HH:mm:ss'), formatDate(endTimeStamp, 'YYYY-MM-DD HH:mm:ss')]
}
